package com.weiawei.Dialog;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;

public class EndingDialog extends baseDialog{

    public static int restart = 1 ;

    public static int back = 0 ;

    private  JButton reStartButton , backButton ;

    private JLabel jLabel ;

    /**
     * @param jFrame 容器
     * @param title  对话框标题
     * @param flag
     */
    public EndingDialog(JFrame jFrame, String title, boolean flag) {
        super(jFrame, title, flag);
        this.init();
    }


    /**
     * 初始化游戏结束的弹窗
     * 初始化选项与内容
     */
    private void init() {

        reStartButton = new JButton("重新开始");
        backButton = new JButton("返回菜单");
        jLabel = new JLabel();

        this.setLeftButton(backButton);
        this.setRightButton(reStartButton);

        jLabel.setFont(new Font(Font.DIALOG_INPUT, Font.BOLD, 15));
        jLabel.setBounds(80, 10, 200, 100);

        add(reStartButton);
        add(backButton);
        add(jLabel);
    }

    /**
     * 设置游戏结束的弹窗标题
     * @param winnerInfo
     */
    public void setWinnerInfo(String winnerInfo){jLabel.setText(winnerInfo);}

    /**
     * 通过用户点击的按钮来触发不同的事件
     * 通过message传递信息，让前端进行反馈和跳转
     * @param e 用户点击的按键
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == reStartButton){
            message = restart ;
            setVisible(false);
        }else if(e.getSource() == backButton){
            message = back;
            setVisible(false);
        }
    }
}
